package cn.wolfcode.trip.base.domain;


import cn.wolfcode.trip.base.util.JsonUtil;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;
@Setter
@Getter
public class Region extends BaseDomain {

    public static final Integer STATE_NOMAL = 0;
    public static final Integer STATE_HOT = 1;
    private String name;

    private Region parent;

    private Integer state;


    public Map toTreeViewMap(){
        Map<Object,Object> map = new HashMap<>();
        map.put("text",name);
        map.put("id",id);
        map.put("json",this.getJson());
        map.put("lazyLoad",true);
        if (state == STATE_HOT){
            map.put("tags",new String[]{"推荐"});
        }
        return map;
    }

    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("name",name);
        map.put("state",state);
        if (parent != null){
            map.put("parentId",parent.getId());
            map.put("parentName",parent.getName());
        }
        return JsonUtil.toJsonString(map);
    }
}